﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HCLSMod.ShowErrorInfo
{

    public interface IZLSysErrorForm
    {
        void SetParent(Control fParent);
    }

    public partial class FErrorEvetInfo : UserControl, IZLSysErrorForm
    {
        protected Exception fErrorEvent = null;

        public Exception ErrorEvent { get { return fErrorEvent; } }

        protected int fIndex = 0;
        public int Index
        {
            get { return fIndex; }
            set
            {
                fIndex = value;
                ShowErrorInfo();
            }
        }

        public FErrorEvetInfo(Exception ex)
        {
            InitializeComponent();
            fErrorEvent = ex;
            ShowErrorInfo();
        }
        public FErrorEvetInfo(string ex)
        {
            InitializeComponent();
            groupBoxErrorTitile.Text = fIndex.ToString() + ":";

            richTextBoxErrorStrInfo.AppendText(ex);
        }
        protected void ShowErrorInfo()
        {
            groupBoxErrorTitile.Text = fIndex.ToString() + ":";
            if (fErrorEvent != null)
            {
                groupBoxErrorTitile.Text += fErrorEvent.GetType().ToString();

                richTextBoxErrorStrInfo.Text = string.Format("{0}[{1}]",
                    fErrorEvent.TargetSite != null ? fErrorEvent.TargetSite.ToString() : "",
                    fErrorEvent.Source != null ? fErrorEvent.Source : "")+"\r\n";

                richTextBoxErrorStrInfo.AppendText(fErrorEvent.Message);
            }
            else
            {
                richTextBoxErrorStrInfo.Clear();
            }
        }

        public void SetParent(Control fParent)
        {
            this.Dock = DockStyle.Top;
            this.Parent = fParent;
            this.Show();
        }                
    }
}
